package cn.dkk.create_design.prototype.deep_clone_prototype;

import java.io.*;


/**
 * 利用IO实现的深克隆工具类
 * @param <T>
 */
public class DeepCloneUtils<T> {

    private final static String PATH = "./1.TXT";

    public static <T> T deepClone(T t) throws Exception {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(PATH));
        oos.writeObject(t);
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(PATH));
        T clone=(T) ois.readObject();
        ois.close();
        oos.close();
        return clone;
    }

}
